package reco.db.validation;

import reco.db.Constraint;

import com.google.common.base.Preconditions;

public class MinConstraintFactory<E extends Comparable<E>> extends SimpleConstraintFactory implements DateConstraintFactory, NumberConstraintFactory {
    private final E min;

    public MinConstraintFactory(E constraintMin) {
        super(expectedTypeOn(constraintMin));
        this.min = constraintMin;
    }

    private static final Class<?> expectedTypeOn(Comparable<?> constraintMin) {
        Preconditions.checkNotNull(constraintMin, "constraintMin");
        return constraintMin.getClass();
    }

    @Override
    protected <T> Constraint<T> createConstraint() {
        @SuppressWarnings("unchecked")
        final Constraint<T> constraint = (Constraint<T>) new MinConstraint<E>(this.min);
        return constraint;
    }
}